<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head><meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"/>
<title>如何获得request|session</title><link href="../zdoc.css" rel="stylesheet" type="text/css"/>
</head>
<body><a name="top"></a>
<div class="zdoc_header">如何获得request|session</div>
<div class="zdoc_author"><em>By:</em><b>Jaron</b></div>
<div class="zdoc_body">
<ul class="zdoc_index_table">
<li>
<div><span class="num">1</span><a href="#方法一、在Controller方法中注入">方法一、在Controller方法中注入</a></div>
</li>
<li>
<div><span class="num">2</span><a href="#方法二、继承BaseController">方法二、继承BaseController</a></div>
</li>
</ul>
<div class="hr"><b></b></div>
<h1><a name="方法一、在Controller方法中注入"></a>方法一、在Controller方法中注入</h1>
<div style="float:right;"><a href="#top">Top</a></div>
<pre>@RequestMapping(method = {GET, POST})
public String list(@ModelAttribute SearchForm searchForm, Model model, HttpServletRequest request) {
	
	HttpSession session = request.getSession();
	......
	return "contact/list";
}
</pre>
<h1><a name="方法二、继承BaseController"></a>方法二、继承BaseController</h1>
<div style="float:right;"><a href="#top">Top</a></div>
<pre>public class ContactController extends BaseController {
	@RequestMapping(method = {GET, POST})
	public String list(@ModelAttribute SearchForm searchForm, Model model) {
		HttpServletRequest request = getHttpServletRequest();
		HttpSession session = getHttpSession();		
		return "contact/list";
	}
}
</pre>
</div>
<div class="zdoc_footer"><em>By:</em><b>Jaron</b></div>
</body>
</html>